package com.kakarote.finance.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.kakarote.core.servlet.BaseServiceImpl;
import com.kakarote.core.utils.BaseUtil;
import com.kakarote.finance.common.AccountSet;
import com.kakarote.finance.entity.PO.FinanceIndicator;
import com.kakarote.finance.entity.PO.FinanceIndicatorTemplate;
import com.kakarote.finance.mapper.FinanceIndicatorTemplateMapper;
import com.kakarote.finance.service.IFinanceIndicatorService;
import com.kakarote.finance.service.IFinanceIndicatorTemplateService;
import com.kakarote.finance.service.IFinanceInitService;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 财务指标模板 服务实现类
 * </p>
 *
 * @author zhangzhiwei
 * @since 2020-04-27
 */
@Service("indicatorTemplateService")
public class FinanceIndicatorTemplateServiceImpl extends BaseServiceImpl<FinanceIndicatorTemplateMapper, FinanceIndicatorTemplate>
        implements IFinanceIndicatorTemplateService, IFinanceInitService {

    @Autowired
    private IFinanceIndicatorService financeIndicatorService;


    @Override
    public void init() {
        List<FinanceIndicatorTemplate> listFinanceIndicatorTemplate = this.lambdaQuery().list();
        if (CollUtil.isEmpty(listFinanceIndicatorTemplate)) {
            return;
        }
        financeIndicatorService.lambdaUpdate().eq(FinanceIndicator::getAccountId, AccountSet.getAccountSetId()).remove();
        List<FinanceIndicator> saveFinanceIndicatorList = new ArrayList<>();
        for(FinanceIndicatorTemplate detail : listFinanceIndicatorTemplate){
            FinanceIndicator financeIndicator = new FinanceIndicator();
            BeanUtils.copyProperties(detail,financeIndicator);
            financeIndicator.setAccountId(AccountSet.getAccountSetId());
            financeIndicator.setId(BaseUtil.getNextId());
            saveFinanceIndicatorList.add(financeIndicator);
        }
        financeIndicatorService.saveBatch(saveFinanceIndicatorList);
    }

    @Override
    public void importTemplate(Sheet sheet) {

    }


    @Override
    public void init(String sheet) {

    }

}
